loginCtrl.$Inject = ['$scope', '$rootScope', '$location', '$http'];
function loginCtrl($scope, $rootScope, $location, $http) {
    $scope.login = function() {
        let isEmpty = false;
        document.querySelectorAll('#loginForm input').forEach(function(value) {
            if (!value.value)
                isEmpty = true;
        })
        if (isEmpty)
            return;

        $http.post('/o2o/login', $scope.merchant).then(function(response) {
            let data = response.data;
            if (data.error) {
                $scope.error = data.error;
                return;
            }
            $rootScope.merchant = data.message;
            $location.path('/merchant/home');
        });
    }
    $scope.register = function() {
        $location.path('/audit/register');
    }
}
module.exports = loginCtrl